package sz.szsmk.citizencard.ui.fragment;

import android.annotation.SuppressLint;
import androidx.fragment.app.Fragment;

import android.view.View;

import java.util.ArrayList;
import java.util.List;

import sz.szsmk.citizencard.DaggerApplication;
import sz.szsmk.citizencard.R;
import sz.szsmk.citizencard.databinding.BusHomeSiteViewBinding;
import sz.szsmk.citizencard.ioc.Compontent.DaggerCommonFragmentComponent;
import sz.szsmk.citizencard.model.network.bean.response.QueryNearStandbyRes;
import sz.szsmk.citizencard.mvp.contract.IBusHomeSiteContact;
import sz.szsmk.citizencard.mvp.presenter.BusHomeSitePresenter;
import sz.szsmk.citizencard.ui.activity.BusHomeActivity;
import sz.szsmk.citizencard.ui.adapter.MyPagerAdapter;
import sz.szsmk.citizencard.ui.base.IBaseFragment;
import sz.szsmk.citizencard.widget.NoScrollViewPager;

/**
 * Copyright (c)2018
 * author: zdh
 * created on: 2018/11/14 17:27
 * description:
 */
@SuppressLint("ValidFragment")
public class BusHomeSiteFragment extends IBaseFragment<BusHomeSitePresenter, BusHomeSiteViewBinding>
        implements IBusHomeSiteContact.IBusHomeSiteView, View.OnClickListener {

    private List<Fragment> fragmentList = new ArrayList<>();
    private NoScrollViewPager busHomeSiteVp;

    public BusHomeSiteFragment(BusHomeActivity busHomeActivity) {
    }

    @Override
    protected int attachLayoutRes() {
        return R.layout.bus_home_site_view;
    }

    @Override
    protected void initInjector() {
        DaggerCommonFragmentComponent.builder().appCompontent(DaggerApplication.getAppComponent())
                .build().inject(this);
    }

    @Override
    protected void initViews() {
        busHomeSiteVp = dataBinding.busHomeSiteVp;
        setTextColor();
        dataBinding.siteTv1.setTextColor(getResources().getColor(R.color.color_00AAFF));
        dataBinding.homeSiteCollecLl.setOnClickListener(this);
        dataBinding.homeSiteNearbyLl.setOnClickListener(this);
        fragmentList.add(BusHomeSiteNearFragment.getInstance());
        fragmentList.add(BusHomeSiteCollecFragment.getInstance());
        MyPagerAdapter myPagerAdapter = new MyPagerAdapter(getChildFragmentManager(), fragmentList);
        busHomeSiteVp.setAdapter(myPagerAdapter);
        busHomeSiteVp.setCurrentItem(0);
        mPresenter.getSearchList("string","string");
    }

    @Override
    protected void updateViews() {

    }

    @Override
    public void getSearchListSucc(QueryNearStandbyRes response) {
        List<QueryNearStandbyRes.BusSiteListBean> busSiteList = response.getBusSiteList();
    }

    @Override
    public void getSearchListFail() {

    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.home_site_collec_ll) {
            busHomeSiteVp.setCurrentItem(1);
            setTextColor();
            dataBinding.siteTv2.setTextColor(getResources().getColor(R.color.color_00AAFF));
            dataBinding.siteIv2.setImageResource(R.drawable.icon_star_blue);
        } else if (id == R.id.home_site_nearby_ll) {
            busHomeSiteVp.setCurrentItem(0);
            setTextColor();
            dataBinding.siteTv1.setTextColor(getResources().getColor(R.color.color_00AAFF));
            dataBinding.siteIv1.setImageResource(R.drawable.icon_location_blue);
        }
    }

    private void setTextColor() {
        dataBinding.siteTv2.setTextColor(getResources().getColor(R.color.color_3d494f));
        dataBinding.siteTv1.setTextColor(getResources().getColor(R.color.color_3d494f));

        dataBinding.siteIv1.setImageResource(R.drawable.icon_location_grey);
        dataBinding.siteIv2.setImageResource(R.drawable.icon_star_grey);
    }
}
